package com.capacitydorm.server.web;

import com.capacitydorm.server.common.vo.LogStudentsVo;
import com.capacitydorm.server.common.vo.PagesVo;
import com.capacitydorm.server.domain.Student;
import com.capacitydorm.server.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService logService;

    @GetMapping
    public ResponseEntity<PagesVo> getLogs(Integer page, Integer rows) {
        try {
            PagesVo result = logService.findLogs(page, rows);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @GetMapping("/{id}")
    public ResponseEntity<LogStudentsVo> getLogs(@PathVariable("id") Integer id) {
        try {
            LogStudentsVo studentList = logService.findStudentList(id);
            return new ResponseEntity<>(studentList, HttpStatus.OK);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}
